package com.map.lbs;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.content.Context;

public class CommentsListAdapter extends BaseAdapter{
	List<Comment> comments;
	private LayoutInflater inflater;
	
	public CommentsListAdapter(List<Comment> comments, Context context){
		this.comments = comments;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		if(comments != null){
			return comments.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if(comments != null){
			return comments.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.comment_row, null);
		}
		
		if(comments != null){
			Comment comment = comments.get(position);
			
			ImageView photo = (ImageView)convertView.findViewById(R.id.comment_photo);
			TextView author = (TextView)convertView.findViewById(R.id.comment_author);
			TextView content = (TextView)convertView.findViewById(R.id.comment_text);
			TextView location = (TextView)convertView.findViewById(R.id.comment_locaton);
			TextView time = (TextView)convertView.findViewById(R.id.comment_time);
			//TODO: should get from comment.photo
			photo.setBackgroundResource(R.drawable.face);
			author.setText(comment.getAuthor());
			content.setText(comment.getContent());
			location.setText(comment.getLocationDesc());
			time.setText(comment.getTime().toString() + " at");
		}
		
		return convertView;
	}

}
